<template>
	<view class="load" v-if="!load">
		<u-loading-icon mode="circle" inactive-color="#fff" text="正在加载..." vertical></u-loading-icon>
	</view>
	<view v-else>
		<u-search inputAlign="center" placeholder="搜索会员昵称/ID号" @search="search()" v-model="searchValue" height="30"
			actionText="取消" :actionStyle="{color:'#fff'}" @custom="celSearch"></u-search>
		<x-scroll :fixed="true" @onRefresh="onRefresh" @scrolltolower="scrolltolower" :refresh="_freshing">
			<view class="list ">
				<view v-if="Array.isArray(list) && list.length > 0" v-for="item in list" :key="item.ID">
					<view class="item wap">
						<view class="cover" @click="nav_to(`/pages/user/user_visitor?ub=-1&id=${item.UserID}`)">
							<image :src="item.HeadImgUrl" mode="aspectFill" />
						</view>
						<view class="con" @click="nav_to(`/pages/user/user_visitor?ub=-1&id=${item.UserID}`)">
							<view class="name f1 c1">
								{{item.Name || "匿名"}}
								<view class="member member_hei" v-if="getUserType(item.UserType) == 1 ">黑金卡</view>
								<view class="member number_huan" v-if="getUserType(item.UserType) == 2">金卡</view>
								<view class="member" v-if="getUserType(item.UserType) == 0">普通用户</view>
							</view>
							<view class="time f2 c3">{{getOnlineTime(item.UpdateTime)}}在线</view>
							<!-- 			<view class="time f2 c3">{{item.PayType}} </view> -->
						</view>
						<view class="money">{{item.TotalRecommendUsers}} / {{item.TotalRecommendRegisterUsers}}
						</view>

					</view>
					<view class="item_set wap" @click="set_show(item)">
						拉新佣金：{{item.NewUser_Commission}}元 消费分成：{{item.F_Commission_Rate}}% 收礼分成：{{item.T_Commission_Rate}}%
					</view>
				</view>

				<block v-else>
					<u-empty mode="list" width="64" height="64"
						icon="https://golfdate.oss-cn-shenzhen.aliyuncs.com/community/20230510114106.png" :show="true"
						iconSize="32" text="暂无数据"></u-empty>
				</block>
			</view>

		</x-scroll>
		
		<uni-popup ref="setting" type="center">
			<view class="pop_con">
				<view class="hd f1">设置代理佣金</view>
				<view class="inp">
					<view class="name">
						拉新佣金(元)
					</view>
					<view class="gradeList">
						<input v-model="NewU_Com" type="number" placeholder="请输入">
					</view>
		
				</view>
				<view class="inp">
					<view class="name">
						消费分成(%，最大15%)
					</view>
					<view class="gradeList">
						<input v-model="Com_Rate" type="number" max="15" placeholder="最大值为15">
					</view>
				</view>
				<view class="inp">
					<view class="name">
						收礼分成(%，最大10%)
					</view>
					<view class="gradeList">
						<input v-model="gift_Com_Rate" type="number" max="10" placeholder="最大值为10">
					</view>
				</view>
				<view class="btns">
					<u-button text="取消" @click="$refs['setting'].close()"></u-button>
					<u-button type="success" text="确定" @click="setting_sub"></u-button>
				</view>
			</view>
		</uni-popup>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				load: false,
				_freshing: true,
				list: [],
				searchValue: '',
				PageIndex: 1, //页码
				PageSize: 10, //请求条数
				isMore: true,

				_PID: '',
				
				sel_user: 0,
				Com_Rate: 0,
				gift_Com_Rate: 0,
				NewU_Com: 0,
			}
		},
		onLoad(e) {

			this._PID = e.id;

			this.init();
		},
		onShow() {

		},
		methods: {

			onRefresh() {
				this.PageIndex = 1;
				this.init();
			},
			//滚动到底部触发
			async scrolltolower() {

			},
			set_show(l) {
				this.sel_user = l.ID;
				this.NewU_Com = l.NewUser_Commission;
				this.Com_Rate = l.F_Commission_Rate;
				this.gift_Com_Rate = l.T_Commission_Rate;
			
				this.$refs['setting'].open();
			},
			async setting_sub() {
			
				let res = await this.$api.post("SaleChannel/SetCommissionInfo", {
					UserID: this.sel_user,
					NewUser_Commission: this.NewU_Com,
					F_Commission_Rate: this.Com_Rate,
					T_Commission_Rate: this.gift_Com_Rate
				});
			
				this.user_list();
			
				this.$refs['setting'].close();
			
			
			},

			async init() {
				console.log('============' + this._PID);

				let res = await this.$api.post('SaleChannel/MyDealers', {
					UserID: this._PID
				});

				console.log(res.data);

				this.list = res.data;

				this.load = true;
			},
			async search() {

				this.list = [];

				let res = await this.$api.post('SaleChannel/MyDealers', {
					UserID: this._PID
				});

				this.list = res.data;

				this.load = true;

			},
			async celSearch() {
				this.searchValue = "";
				this.search();
			}

		},
		computed: {

			getUserType(l) {
				return l => {
					if (l.indexOf('黑金') != -1) {
						return 1
					} else if (l.indexOf('金') != -1) {
						return 2
					} else if (l.indexOf('银') != -1) {
						return 3
					} else {
						return 0
					}
				}
			},
			getOnlineTime(time) {
				return time => {
					console.log(time);
					let d = new Date(time).valueOf();
					return uni.$u.timeFrom(d);
				}
			}
		}
	}
</script>

<style lang="scss">
	.list {
		.item_set{
			display: flex;
			height: 80rpx;
			align-items: center;
			color: #ffaa00;
		}
		.item {
			display: flex;
			height: 150rpx;
			align-items: center;

			.cover {
				height: 100rpx;
				width: 100rpx;
				border-radius: 50%;
				overflow: hidden;
				border: 1px solid #333;

				image {

					height: 100%;
					width: 100%;
				}
			}

			.con {
				padding-left: 20rpx;
				flex: 1;

				.time {
					margin-top: 10rpx;
				}
			}

			.money {
				height: 48rpx;
				line-height: 48rpx;
				text-align: center;
				color: #fff;
			}

			.member {
				display: inline-block;
				vertical-align: middle;
				width: 68rpx;
				height: 32rpx;
				text-align: center;
				color: #fff;
				font-size: 16rpx;
				line-height: 32rpx;
				margin-left: 20rpx;
			}

			.number_huan {
				color: #4C310C;
				background: linear-gradient(180deg, #FDF9F6 0%, #E1C4A6 100%);
				border: 2rpx solid #E6CEB5;
			}

			.number_hei {
				color: #ffffff;
				background: linear-gradient(135deg, #7E7E7E 0%, #292929 100%);
				border: 2rpx solid #E6CEB5;
			}


		}


	}
	
	
	.pop_con {
		height: 680rpx;
		background: #fff;
		width: 650rpx;
		border-radius: 16rpx;
		border: 1px solid #FEF0BC;
	
		.hd {
			height: 80rpx;
			line-height: 80rpx;
			border-bottom: 1px solid #eee;
			text-align: center;
			color: #333;
			font-weight: bolder;
		}
	
		.inp {
			margin-top: 30rpx;
			padding-left: 30rpx;
			padding-right: 30rpx;
			display: flex;
			flex-direction: column;
	
			.name {
				color: #000;
				height: 60rpx;
				line-height: 60rpx;
				margin-bottom: 10rpx;
			}
	
			.gradeList {
				width: 100%;
				display: flex;
				justify-content: space-between;
	
				.grade {
					box-sizing: border-box;
					height: 60rpx;
					width: 160rpx;
					text-align: center;
					line-height: 60rpx;
					border-radius: 10rpx;
					font-size: 14px;
					color: #333;
					border: 1px solid #FEF0BC;
					margin-left: 12rpx;
				}
	
				.cycle {
					background-color: #333;
					color: #fff;
				}
	
				input {
					color: #7c7c7c;
				}
			}
	
		}
	
		.btns {
			margin-top: 40rpx;
			display: flex;
			padding-left: 30rpx;
			padding-right: 30rpx;
			justify-content: space-between;
	
			/deep/ .u-button__text {
				color: #333;
			}
	
			/deep/ .u-button--success {
				text {
					color: #fff !important;
				}
	
				background: linear-gradient(180deg, #FEF0BC 0%, #B98B51 100%);
			}
	
			/deep/ .u-button {
				width: 290rpx;
			}
		}
	}
</style>